package com.chenxi;

import java.util.concurrent.locks.ReentrantLock;
/*
getHoldCount()方法
getHoldCount()方法的作用是查询当前线程保持此锁定的个数，也就是调用lock()方法的次数。
 */
public class MyGetHoldCount {

    private ReentrantLock lock = new ReentrantLock();
    public void serviceLock1(){
        try {
            lock.lock();
            System.out.println("serviceLock1 :" + lock.getHoldCount());
            this.serviceLock2();
        }finally {
            lock.unlock();
        }
    }

    public void serviceLock2(){
        try {
            lock.lock();
            System.out.println("serviceLock2 :" + lock.getHoldCount());
        }finally {
            lock.unlock();
        }
    }

    public static void main(String[] args) {
        new MyGetHoldCount().serviceLock1();
    }
}
